﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Content/Master.Master" Inherits="System.Web.Mvc.ViewPage<SCS.Core.Models.Collection.TypeProductCollection>" %>
<%@ Import Namespace="SCS.Core" %>
<%@ Import Namespace="SCS.Core.Models" %>
<%@ Import Namespace="SCS.Core.ViewModels" %>
<%@ Import Namespace="SCS.Core.Controllers" %>
<%@ Import Namespace="SCSService" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Type Product
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript" src="/ThemeExtends/AdminSkin/js/jquery.flot.js"></script>
    <script type="text/javascript" src="/ThemeExtends/AdminSkin/js/jquery.flot.stack.js"></script>	
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/jquery-ui-1.8.13.custom.css"/>
    <link rel="stylesheet" type="text/css" href="/Content/smoothness-1.8.13/ui.dropdownchecklist.themeroller.css"/>
    <script type="text/javascript" src="/Scripts/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-ui-1.8.13.custom.min.js"></script>
    <script type="text/javascript" src="/Scripts/ui.dropdownchecklist-1.4-min.js"></script>
    <script type="text/javascript" src="/Scripts/ui.dropdownchecklist.js"></script>
    <%--Validator--%>
    <script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
    <script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/Content/popup.css" />

    <script type="text/javascript">
       
        function InsertTypeItems() {
          
            //string TypeProductName, string TypeProductDes, string TypeProductAbstract, string Title, string MetaKeyword, 
            //string MetaDescription, int LanguagesID
            var typeProductName = document.getElementById("TypeProductName_Items").value;
            if (typeProductName == "") {
                return alert('Xin vui lòng nhập tên danh mục');
            }
            var typeProductDes = document.getElementById("TypeProductDes_Items").value;
            var typeProductAbstract = document.getElementById("TypeProductAbstract_Items").value;
            var title = document.getElementById("Title_Items").value;
            var e = document.getElementById("ListLanguagesID");
            var languagesID = e.options[e.selectedIndex].value;
            var metaKeyword = document.getElementById('MetaKeyword_Items').value;
            var metaDescription = document.getElementById('MetaDescription_Items').value;

            var ids = [typeProductName, typeProductDes, typeProductAbstract, title, metaKeyword, metaDescription, languagesID];
            $.ajax({
                url: '<%=Url.Action("SaveAddTypeProductItem","Stock")%>',
                data: { ids: ids },
                type: "POST",
                traditional: true,
                success: function (data) {
                    var values = document.getElementById('ArrTypeItemsID').value;
                    if (data != '0') {
                        values +=","+ data;
                    }

                    if (document.all || document.getElementById) {
                        document.getElementById('ArrTypeItemsID').value = values;
                    }
                    else {
                        document.getElementById('ArrTypeItemsID').setAttribute("value", values);
                    }
                }
            });

            document.getElementById("mysubmit").innerHTML = '<input type="submit" value="Save" class="button themed"/>';
            alert("Thêm mới ngôn ngữ thành công!");
//            document.getElementById("TypeProductName_Items").value = "";
//            document.getElementById("TypeProductDes_Items").value = "";
//            document.getElementById("TypeProductAbstract_Items").value = "";
//            document.getElementById("Title_Items").value = "";
//            var ec = document.getElementById("ListLanguagesID");
//            document.getElementById('MetaKeyword_Items').value = "";
//            document.getElementById('MetaDescription_Items').value = "";
        }
    </script>
    
    <script type="text/javascript">
        function UpdateTypeItems() {
            
            //string TypeProductName, string TypeProductDes, string TypeProductAbstract, string Title, string MetaKeyword, 
            //string MetaDescription,int TypeProductID, int LanguagesID,int TypeProductItemID
            var typeProductName = document.getElementById("TypeProductName_Items").value;
            if (typeProductName == "") {
                return alert('Xin vui lòng nhập tên danh mục');
            }
            var typeProductDes = document.getElementById("TypeProductDes_Items").value;
            var typeProductAbstract = document.getElementById("TypeProductAbstract_Items").value;
            var title = document.getElementById("Title_Items").value;
            var e = document.getElementById("ListLanguagesID");
            var languagesID = e.options[e.selectedIndex].value;
            var metaKeyword = document.getElementById('MetaKeyword_Items').value;
            var metaDescription = document.getElementById('MetaDescription_Items').value;
            var typeProductID = document.getElementById('TypeProductID').value;
            var typeProductItemID = document.getElementById('TypeProductItemID').value;
            var ids = [typeProductName, typeProductDes, typeProductAbstract, title, metaKeyword, metaDescription, typeProductID, languagesID, typeProductItemID];
            $.ajax({
                url: '<%=Url.Action("UpdateTypeProductItem","Stock")%>',
                data: { ids: ids },
                type: "POST",
                traditional: true,
                success: function (data) {
                    var result = document.getElementById('Result').value;
                    document.getElementById('Result').value = data;
                }
            });

            alert("lưu thành công!");
            document.getElementById("mysubmit").innerHTML = '<input type="submit" value="Save" class="button themed"/>';

            document.getElementById("TypeProductName_Items").value = "";
            document.getElementById("TypeProductDes_Items").value = "";
            document.getElementById("TypeProductAbstract_Items").value = "";
            document.getElementById("Title_Items").value = "";
            var ec = document.getElementById("ListLanguagesID");
            document.getElementById('MetaKeyword_Items').value = "";
            document.getElementById('MetaDescription_Items').value = "";
        }
    </script>
    <script type="text/javascript">

        function GetItems(dropDownList) {
            // var selectedReport = dropDownList.options[dropDownList.selectedIndex];
            var selectedReport = document.getElementById("ListLanguagesID").value;
            var values = document.getElementById('TypeProductID').value;
            var ids = [selectedReport, values];
            $.ajax({
                url: '<%=Url.Action("GetTypePByLandTypeProductId","Stock")%>',
                data: { ids: ids },
                type: "POST",
                traditional: true,
                //contentType: "application/json; charset=utf-8",
                //dataType: "json",
                success: function (result) {
                    $('#TypeProductName_Items').val(result.split("|")[1]);
                    $('#TypeProductDes_Items').val(result.split("|")[2]);
                    $('#TypeProductAbstract_Items').val(result.split("|")[3]);
                    $('#Title_Items').val(result.split("|")[4]);
                    $('#MetaKeyword_Items').val(result.split("|")[5]);
                    $('#MetaDescription_Items').val(result.split("|")[6]);
                    $('#TypeProductItemID').val(result.split("|")[0]);

                }
            });
        }
    
    </script>

          <!--Popup-->
     
     <script type="text/javascript">
         $(document).ready(function () {
             
             //When you click on a link with class of poplight and the href starts with a #  
             $('a.poplight[href^=#]').click(function () {
                 var popID = $(this).attr('rel'); //Get Popup Name 
                 var popURL = $(this).attr('href'); //Get Popup href to define size 

                 //Pull Query & Variables from href URL 
                 var query = popURL.split('?');
                 var dim = query[1].split('&');
                 var popWidth = dim[0].split('=')[1]; //Gets the first query string value 

                 //Fade in the Popup and add close button 
                 $('#' + popID).fadeIn().css({ 'width': Number(popWidth) }).prepend('<a href="#" class="close"><img src="/Content/images/popup-closeButton.png" class="btn_close" title="Close Window" alt="Close" /></a>');
                 document.getElementById("viewbutton").innerHTML = '<a href="#" class="close"><div class="button themed" style="float:left;width: 61px;">Đóng lại</div></a>';
                 //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css 
                 var popMargTop = ($('#' + popID).height() + 80) / 2;
                 var popMargLeft = ($('#' + popID).width() + 80) / 2;

                 //Apply Margin to Popup 
                 $('#' + popID).css({
                     'margin-top': -popMargTop,
                     'margin-left': -popMargLeft
                 });

                 //Fade in Background 
                 $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag. 
                 $('#facebox_overlay').css({ 'filter': 'alpha(opacity=80)' }).fadeIn(); //Fade in the fade layer  

                 return false;
             });


             //Close Popups and Fade Layer 
             $('a.close, #facebox_overlay').live('click', function () { //When clicking on the close or fade layer... 
                 $('#facebox_overlay , .popup_block').fadeOut(function () {
                     $('#facebox_overlay, a.close').remove();
                 }); //fade them both out 

                 return false;
             });


         }); 
    </script> 
    <script type="text/javascript">
        function check() {
                var arrayid = document.getElementById("ArrTypeItemsID").value;
                if (arrayid == "") {
                    alert("Bạn chưa dịch ngôn ngữ!");

                }
           

               
//            document.getElementById("mysubmit").onclick = function () {
//                var arrayid = document.getElementById("ArrTypeItemsID").value;
//                if (arrayid == "") {
//                    alert("chưa dịch ngôn ngữ!");
//                    return false;
//                }
//            }
        }
    </script>

    <% Html.EnableClientValidation(); %>
   
         <% using (Html.BeginForm((bool)ViewData["IsAdd"] ? "SaveAddLanguage" : "SaveEditLanguage", "Stock", FormMethod.Post, new { siteGuid = "sendFileForm", language = "sendFileForm", id = "sendFileForm", enctype = "multipart/form-data" }))
            {%>
            
     <div class="clear"></div>
       
        <div class="box ">
		    <h2 class="box-header"><%=(bool)ViewData["IsAdd"] ? "Tạo mới danh mục sản phẩm" : "Sửa Danh mục sản phẩm" %></h2>
		    <div class="box-content">

                <label class="form-label"> Tên Danh mục </label>
                <%= Html.TextBoxFor(m => m.TypeProductName, new { @class = "form-field width30" })%> <span style="color:Red;font-weight:bold"><%= Html.ValidationMessageFor(m => m.TypeProductName) %></span>
                
                 <%
                SelectList data = (SelectList)ViewData["ListLanguage"];
                if (data.ToList().Count > 1)
                   { %>
                <a href="#?w=600" rel="popup_name" class="poplight"  style="float:right;clear:right;"><div class="button themed">Dịch sản phẩm</div></a> 
                <%} %>
                
                

                <label class="form-label"> Params </label>
                 <%= Html.TextBoxFor(m => m.TypeProductParam, new { @class = "form-field half" })%>

                 <label class="form-label"> Mô tả </label>
                 <%= Html.TextAreaFor(m => m.TypeProductDes, new { @class = "form-field half" })%>
                   
                 <label class="form-label"> Chọn ảnh  </label>
                 
                 

                 <%if (Model.TypeProductImage != null)
                   {
                       string src = Model.TypeProductImage;
                       
                           %>
                            <img src="http://image.atf.com.vn/<%=Model.TypeProductImage %>" width="130px" alt="" id="imgname" onclick="window.open('/Editor/aspnet/Images.aspx','images',' width=750,height=450,left=150,top=200,toolbar=no,status=0,scrollbars=1,location=0,');" />  
                           <%
                   }
                   else
                   { 
                   %>
                     <img src="/Content/images/noimage.gif" width="130px" id="imgname" alt="" onclick="window.open('/Editor/aspnet/Images.aspx','images',' width=750,height=450,left=150,top=200,toolbar=no,status=0,scrollbars=1,location=0,');" />
                   <%
                   }
                  %>
                 <input type="hidden" id="url" name="url"/>
                  
                  <label class="form-label"> Chọn ngôn ngữ  </label>
                    <%= Html.DropDownList("LanguagesID", (SelectList)ViewData["ListLanguage"], "--Chọn ngôn ngữ--", new { @class = "width20" })%>        
                    <%=Html.HiddenFor(m=>m.LanguagesID) %>
                 <label class="form-label"> Thuộc Danh mục </label>
                 <%= Html.DropDownList("ParentTypeProductID", (SelectList)ViewData["ListParent"], "--Danh mục chính--", new { @class = "width20" })%>
                 
                 <label class="form-label"> Kích hoạt </label>
                 <%if (Model.TypeProductStatus == 1)
                   {
                   %>
                        <%=Html.CheckBox("TypeProductStatus", true)%>
                   <%
                     }
                   else
                   {
                       if ((bool)ViewData["IsAdd"])
                       {
                       %>
                        <%=Html.CheckBox("TypeProductStatus", true)%>
                       <%
                       }
                       else
                       { 
                       %>
                        <%=Html.CheckBox("TypeProductStatus", false)%>
                        
                       <%
                       }
                    
                   } 
                    %>

                <label class="form-label">Metadata Title </label>
                <%= Html.TextBoxFor(m => m.Title, new { @class = "form-field small" })%>

                <label class="form-label">Metadata Keyword </label>
                <%= Html.TextBoxFor(m => m.MetaKeyword, new { @class = "form-field half" })%>

                <label class="form-label">Metadata Description </label>
                 <%= Html.TextAreaFor(m => m.MetaDescription, new { @class = "form-field small" })%>

                 <%=Html.TextBoxFor(m => m.TypeProductID, new {@Style="display:none" })%>

                
                 
                <%=ViewData["Result"]%>
                
                 
                 <div id="mysubmit" name="mysubmit" style="float:left;">
               <% 
                if (data.ToList().Count > 1)
                { %>
                 <% if ((bool)ViewData["IsAdd"])
                    {%>
                 
                 <div id="divsubmit" name="divsubmit" class="button white_input save_input" style="width: 74px;height: 28px; float:left; margin-right:10px;" onclick="check()"> </div>
                 <a class="button white" href="javascript:history.back();"><span class="icon_text cancel"></span>Đóng</a> <!--Button Close-->
                 <%}
                  else
                  {%>
                  <input type="submit" value="" class="button white_input save_input "/> <!--Button Save-->
                  <a class="button white" href="javascript:history.back();"><span class="icon_text cancel"></span>Đóng</a> <!--Button Close-->
                 <%}
                }
                else
                { %>
                  <input type="submit" value="" class="button white_input save_input " style="width: 74px;height: 28px; float:left; margin-right:10px;"/> <!--Button Save-->
                  <a class="button white" href="javascript:history.back();"><span class="icon_text cancel"></span>Đóng</a> <!--Button Close-->
               <%} %>
                 </div>
                 
               
                 <%
                    if ((bool)ViewData["IsAdd"])
                    {

                    }
                    else
                    { 
                    %> 
                        <%= Html.ActionLink("Sản phẩm", "ListProduct", "Stock", new { id = Model.TypeProductID }, new { @class = "button themed" })%>   
                    <%
                    }  
                 %>
                    
                 
	        </div>
	    </div>
        <div class="clear"></div>
    
     
    

                
                <div id="popup_name" class="popup_block" >                                
                    <div id="TemplateTable" style=" width:auto; float:left;" > </div>
                    <div id="ItemPage" class="box-content" style="height:500px; overflow:scroll;">
                           <div class="clear"></div>
                            
		                        
                                        
                                        <label class="form-label"> Chọn ngôn ngữ  </label>
                                        <% bool tran = true;
                                           if ((bool)ViewData["IsAdd"])
                                           { 
                                               %>
                                                    <%= Html.DropDownList("ListLanguagesID", (SelectList)ViewData["ListLanguage"], "--Chọn ngôn ngữ--", new { @class = "width20", @Style="width:160px;" })%>  
                                               <% 
                                            }
                                           else
                                           { 
                                                %>
                                                    <%= Html.DropDownList("ListLanguagesID", (SelectList)ViewData["ListLanguage"], "--Chọn ngôn ngữ--", new { @class = "width20", onchange = "GetItems(this);",@Style="width:160px;" })%>  
                                                <%
                                           }
                                         %>

                                        

                                        <label class="form-label"> Tên Danh mục </label>
                                        <input type="text" id="TypeProductName_Items" class="form-field half" />

                                        <label class="form-label"> Mô tả </label>
                                        <input type="text" id="TypeProductDes_Items" class="form-field half" style="width:508px;height:60px;" />

                                        <label class="form-label"> Tóm tắt </label>
                                        <input type="text" id="TypeProductAbstract_Items" class="form-field half" style="width:508px;height:90px;"/>

                                        <label class="form-label">Metadata Title </label>
                                        <input type="text" id="Title_Items" class = "form-field small" style="width:300px;"/>

                                        <label class="form-label">Metadata Keyword </label>
                                        <input type="text" id="MetaKeyword_Items" class="form-field half" style="width:508px;" />

                                        <label class="form-label">Metadata Description </label>
                                        <input type="text" id="MetaDescription_Items" class="form-field half" style="width:508px;"  />

                                        
                                       <%-- 
	                                    <% 
                                           if ((bool)ViewData["IsAdd"])
                                           { 
                                               %>
                                                    <a href="#"  onclick="InsertTypeItems()" style="float:right;clear:right;"><div class="button themed">Lưu</div></a> 
                                               <% 
                                            }
                                           else
                                           { 
                                                %>
                                                    <a href="#"  onclick="UpdateTypeItems()" style="float:right;clear:right;"><div class="button themed">Lưu</div></a> 
                                                <%
                                           }
                                         %>--%>
                                         <div style="padding:10px;">
                                        <div style="float:left; margin-right:5px;">
                                    
	                                    <% 
                                           if ((bool)ViewData["IsAdd"])
                                           { 
                                               %>
                                                    <a href="#"  onclick="InsertTypeItems()" ><div class="button themed">Lưu</div></a> 
                                                                                                        
                                               <% 
                                            }
                                           else
                                           { 
                                                %>
                                                           
                                                    <a href="#"  onclick="UpdateTypeItems()" ><div class="button themed">Lưu</div></a> 
                                                      
                                                <%
                                           }
                                         %>
                                       </div>
                                       <div id="viewbutton" style="float:left;">
	                                    <a href="#" class="close"> <div class="button themed" style="float:left;width:61px;">Đóng lại</div> </a>
                                       </div>
                                    </div>
	                       
                            <div class="clear"></div>     
                    </div>                                                        
                </div>  
    <%=Html.Hidden("ArrTypeItemsID")%> 
    <%=Html.Hidden("TypeProductItemID")%>  
    <%=Html.Hidden("Result") %>
    <% } %>
</asp:Content>
